import { Layout, message } from 'antd'
import React, { Fragment, useEffect } from 'react'
import { useHistory } from 'react-router-dom'
import Sider from '../../components/Sider'
import Header from '../../components/Header'
import Content from '../../components/Content'
import { getUserNickname } from '../../util'
import "./index.css"

// 判断是否登陆
function useIsLogin() {
    const history = useHistory()
    useEffect(() => {
        if (!getUserNickname()) {
            history.replace('/login')
            message.error('抱歉，你未登陆，请先登陆')
            return;
        }
    }, [])
}

const { Footer } = Layout;

const Admin = () => {
    useIsLogin()

    return (
        <Fragment>
            <Layout style={{ minHeight: '100vh' }}>
                <Sider />
                <Layout className="site-layout">
                    <Header />
                    <Content/>
                    <Footer style={{ textAlign: 'center' }}>Ant Design ©2021 Created by Ant UED</Footer>
                </Layout>
            </Layout>
        </Fragment>
    )
}

export default Admin
